IF exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetQuestionnaireAnswer]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetQuestionnaireAnswer]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO   
/******************************************************************  
* Name:   GetQuestionnaireAnswer  
* Purpose:  Retrieves a QuestionnaireAnswer based on the QuestionnaireAnswer's  
*     id passed in as a parameter.  
*  
* PARAMETERS  
* Name      Description       
* -------------   -------------------------------------------  
* @id   The Id of the QuestionnaireAnswer to be retrieved.  
******************************************************************/  
  
CREATE Procedure [dbo].[GetQuestionnaireAnswer] (  
  @id  INTEGER   
)  
AS  
BEGIN  
  
 SET NOCOUNT ON  
  
 Select   QA.Id,  
     QA.QuestionnaireVersionId,   
     QA.Name,  
     QA.Required,  
     QA.Editable,  
     Q.Category as 'QuestionnaireCategory',  
     QA.LastModifiedDate,  
     QA.ExternalId,  
     QA.IsClone,  
     QA.ActionTypeId,  
     QA.Highlight,
	 QA.LastModifiedByAdmPersonId ,
	 ADP.LastName+', '+ ADP.FirstName  as LastModifiedBy     
    FROM QuestionnaireAnswer QA  
     INNER JOIN QuestionnaireVersion QV   
      on QA.QuestionnaireVersionId = QV.ID  
     INNER JOIN Questionnaire Q  
      on QV.QuestionnaireId = Q.Id
	 LEFT JOIN AdmPerson ADP
	  on ADP.Id = QA.LastModifiedByAdmPersonId  
   WHERE QA.Id = @id  
   
END  
  